package com.hcrazy.manchester.app.jdbc;

import java.util.ArrayList;
import java.util.List;

import com.hcrazy.manchester.app.pojo.UserGroup;

public class UserGroupDAO extends BaseDAO<UserGroup>{

	public void addUserGroup(List<UserGroup> groups) throws Exception {
		String sql = "insert into him_user_group(groupName,expLowerLimit,expUperLimit,description_mc,picture) values (?,?,?,?,?)";
		List<Object[]> list = new ArrayList<Object[]>();
		if(null != groups && !groups.isEmpty()){
			for(UserGroup group:groups){
				Object[] objs = new Object[]{group.getGroupName(),group.getExpLowerLimit(),
						group.getExpUperLimit(),group.getDescription_mc(),group.getPicture()};
				list.add(objs);
			}
			getJdbcTemplate().batchUpdate(sql, list);
		}
		
	}
	
	public void deleteAll() throws Exception {
		String sql = "delete from him_user_group";
		this.commonUpdate(sql);
	}
	
	public List<UserGroup> listAllGroups() throws Exception{
		String sql = "select * from him_user_group order by expLowerLimit";
		return getList(sql, UserGroup.class);
	}
	
	public UserGroup getById(int groupId) throws Exception{
		String sql = "select * from him_user_group where groupId = ?";
		return this.getJavaBean(sql, UserGroup.class, groupId);
	}
	
	public void delUserGroup(int groupId) throws Exception{
		String sql = "delete from him_user_group where groupId = ?";
		this.commonUpdate(sql, groupId);
	}
	
}
